<!--
 * @Author: your name
 * @Date: 2021-06-07 13:51:37
 * @LastEditTime: 2021-06-08 15:54:24
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bazai_ebook\src\components\ebook\EbookSettingTheme.vue
-->
<template>
  <transition name="slide-up">
    <div class="setting-wrapper" v-show="menuVisible && settingVisible === 1">
      <div class="setting-theme">
        <div
          class="setting-theme-item"
          v-for="(item, index) of themeList"
          :key="'item' + index"
          @click="setTheme(themeList[index])"
        >
          <div
            class="preview"
            :class="{'selected': item.name === defaultTheme }"
            :style="{background: item.style.body.background}"
          ></div>
          <div class="text" :class="{'selected': item.name === defaultTheme }">{{$t(item.alias)}}</div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { defineComponent } from 'vue'
import { useStore } from 'vuex'
import { ebookMixin } from '@/mixins/mixin'
import { saveTheme } from '@/utils/localStorage'
import { initGlobalStyle } from '@/utils/book'
export default defineComponent({
  mixins: [ebookMixin],
  name: 'EbookSettingTheme',
  setup () {
    const store = useStore()
    const setTheme = (theme) => {
      const fileName = store.getters['book/fileName']
      store.dispatch('book/setDefaultTheme', theme.name).then(() => {
        store.getters['book/currentBook'].rendition.themes.select(store.getters['book/defaultTheme'])
        initGlobalStyle(theme.name)
      })
      saveTheme(fileName, theme.name)
    }
    return {
      setTheme
    }
  }
})
</script>
<style lang="scss" scoped>
 .setting-wrapper {
    position: absolute;
    bottom: px2rem(48);
    left: 0;
    z-index: 160;
    width: 100%;
    height: px2rem(90);
    background: white;
    box-shadow: 0 px2rem(-8) px2rem(8) rgba(0, 0, 0, .15);
    .setting-theme {
      height: 100%;
      display: flex;
      .setting-theme-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: px2rem(5);
        box-sizing: border-box;
        .preview {
          flex: 1;
          border: px2rem(1) solid #ccc;
          box-sizing: border-box;
          &.selected {
            box-shadow: 0 px2rem(4) px2rem(6) 0 rgba(0, 0, 0, .1);
          }
        }
        .text {
          flex: 0 0 px2rem(20);
          font-size: px2rem(14);
          color: #ccc;
          @include center;
          &.selected {
            color: #333;
          }
        }
      }
    }
  }
</style>
